package com.gw.booking.util;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Created by roger on 2017/7/5.
 * 快100接口调用
 */
public class Kuai100Util {
    static String key = "ebed6c3ad082c4b5";
    static String apiUrl = "http://www.kuaidi100.com/applyurl?key=" + key;
    static Logger logger = LoggerFactory.getLogger(Kuai100Util.class);

    public static Object getShippingInfo(String kuai100Code, String shippingNo) {
        try {
            return IOUtils.toString(getApiUrl(kuai100Code, shippingNo), "UTF-8");
        } catch (IOException e) {
            logger.error("取物流信息报错", e);
        }

        return null;
    }

    private static URL getApiUrl(String com, String nu) {
        try {
            return new URL(apiUrl + "&com=" + com + "&nu=" + nu);
        } catch (MalformedURLException e) {
            logger.error("取物流接口报错", e);
        }

        return null;
    }
}
